{* Affiliate program settings and info *}
<script language="javascript" type="text/javascript">
<!--
window.reloadURL = '{$REQUEST_URI}';
//-->
</script>
{if $safemode}<div class="error_msg_f">{"msg_safemode_warning"|translate}</div>{/if}
<table>
<tr>
<td nowrap="nowrap">

{* recruited customers table *}

{"affp_referred_customers"|translate}: {$RecruitedCustomersNumber}
<form action="{$REQUEST_URI}" method="POST" name="form_cancel_customer" style="display:none;">
<input name="fACTION" value="CANCEL_CUSTOMER" type="hidden" />
<input name="fREDIRECT" value="{$REQUEST_URI}" type="hidden" />
<input name="CUSTOMER[customerID]" value="" type="hidden" />
</form>
{if $RecruitedCustomersNumber}
<table class="grid">
<tr class="gridsheader">
	<td>
		{"usr_custinfo_login"|translate}
	</td>
	<td nowrap="nowrap">{"usr_account_state"|translate}</td>
	<td nowrap="nowrap">
		{"usr_custinfo_regtime"|translate}
	</td>
	<td></td>
</tr>

{foreach from=$RecruitedCustomers item=_Customer}
<tr class="{cycle values='gridline,gridline1'}">
	<td>
		<a href='{"userID=`$_Customer.customerID`"|set_query_html}'>{$_Customer.Login|default:$_Customer.Email}</a>
	</td>
	<td align="center">
		{if $_Customer.ActivationCode}
			{"usr_account_notactivated"|translate}
		{else}
			{"usr_account_activated"|translate}
		{/if}
	</td>
	<td align="center">
		{$_Customer.reg_datetime}
	</td>
	<td><a href="javascript:void(0)" onclick="
			if(!confirm('{"cnfrm_areyousure"|translate}'))return false;
			document.form_cancel_customer.elements['CUSTOMER[customerID]'].value = {$_Customer.customerID};
			document.form_cancel_customer.submit();
			return false;
			" title="{"affp_remove_user"|translate}"><img src="./images_common/remove.gif" alt="{"affp_remove_user"|translate}" /></a></td>
</tr>
{/foreach}
<tr class="gridsfooter">
	<td colspan="4"></td>
</tr>
</table>

{/if}{* if $RecruitedCustomersNumber *}

{* calendar form *}

<hr />
<b style="font-size:110%">{"affp_commission_payments"|translate}</b>

<br /><br />
<b>{"str_indicate_period"|translate}</b>
<form method="POST" action="{$REQUEST_URI}">
{if $Error_DateFormat}
<div class="error_msg_f">{"affp_msg_error_date_format"|translate}</div>
{/if}
{"str_from"|translate}: <input type="text" name="from" value="{$from}" size="12" /> {"str_to"|translate}: <input name="till" value="{$till}" type="text" size="12" /> <input value="{"btn_view"|translate}" type="submit" />
</form>
{if !$show_tables}
{"msg_timeframe_isnot_specified"|translate}
{/if}

<hr />

{* commissions table *}

{if $show_tables}
<b>{"affp_customer_commissions"|translate} ({"str_from"|translate} {$from} {"str_to"|translate} {$till})</b> 

{if $delete_commission}<div class="ok_msg_f">{"affp_msg_commission_deleted"|translate}</div>{/if}
{/if}{* if $show_tables *}

<p><a href="{"ukey=admin_affprogram&edCustomerID=`$edCustomerID`"|set_query}#new_commission_anchor">{"affp_submit_new_commission"|translate}</a></p>

{if $CommissionsNumber and $show_tables}
	<form action="{$REQUEST_URI}" method="POST" name="form_delete_commission" style="display:none;">
	<input name="fACTION" value="DELETE_COMMISSION" type="hidden" />
	<input name="fREDIRECT" value="{$REQUEST_URI}" type="hidden" />
	<input name="COMMISSION[cID]" value="" type="hidden" />
	</form>

	<table width="100%" class="grid">
	<tr class="gridsheader">
		{assign var=GridHeaders value=$GridHeadersC}
		{include file="backend/gridheader.tpl.html"}
		<td width="1%">&nbsp;</td>
		<td width="1%">&nbsp;</td>
	</tr>
	{foreach from=$Commissions item=_Commission}
	{assign_array var="TotalCommissionsAmount" index=$_Commission.CurrencyISO3 value=$TotalCommissionsAmount[$_Commission.CurrencyISO3]+$_Commission.Amount}
	<tr class="{cycle values='gridline,gridline1'}">
		<td>C-{$_Commission.cID}</td>
		<td>{$_Commission.xDateTime}</td>
		<td>{$_Commission.Description}</td>
		<td nowrap="nowrap">{$_Commission.Amount} {$_Commission.CurrencyISO3}</td>
		<td class="normal"><a href="#" onclick="open_window('{"sub_page=edit_commission&cID=`$_Commission.cID`"|set_query}',500,400);return false;">{"btn_edit"|translate}</a></td>
		<td><a href="javascript:void(0)" onclick="
			if(!confirm('{"cnfrm_areyousure"|translate}'))return false;
			document.form_delete_commission.elements['COMMISSION[cID]'].value = {$_Commission.cID};
			document.form_delete_commission.submit();
			return false;
			" title="{"btn_delete"|translate}"><img src="images_common/remove.gif" alt="{"btn_delete"|translate}" /></a></td>
	</tr>
		{/foreach}
		<tr class="background1 gridsfooter">
			<td colspan="1" valign="top">
				<strong>{"str_total"|translate}</strong>
			</td>
			<td colspan="5" align="right">
				<table align="right">
				{foreach from=$TotalCommissionsAmount key=_key item=_total}
					<tr><td align="right" style="border-width:0px;padding:0px">{$_total|string_format:"%.2f"} {$_key}</td></tr>
				{/foreach}
				</table>
			</td>
		</tr>
	</table>
{elseif $show_tables}
	<br /><br />{"affp_msg_nocommisisons_found"|translate}
{/if}{* if $CommissionsNumber and show_tables *}

{* payments table *}

<hr />

{if $show_tables}
<b>{"affp_payments_to_customers"|translate} ({"str_from"|translate} {$from} {"str_to"|translate} {$till})</b>

{if $delete_payment}<div class="ok_msg_f">{"affp_msg_payment_deleted"|translate}</div>{/if}
{/if}{* if $show_tables *}

<p><a href="{"ukey=admin_affprogram&edCustomerID=`$edCustomerID`"|set_query}#new_payment_anchor">{"affp_submit_new_payment"|translate}</a></p>

{if $PaymentsNumber and $show_tables}
	<form action="{$REQUEST_URI}" method="POST" name="form_delete_payment" style="display:none;">
	<input name="fACTION" value="DELETE_PAYMENT" type="hidden" />
	<input name="fREDIRECT" value="{$REQUEST_URI}" type="hidden" />
	<input name="PAYMENT[pID]" value="" type="hidden" />
	</form>
	
	<table width="100%" class="grid">
		<tr class="gridsheader">
		{assign var=GridHeaders value=$GridHeadersP}
		{include file="backend/gridheader.tpl.html"}
			<td width="1%">&nbsp;</td>
			<td width="1%">&nbsp;</td>
		</tr>
		{foreach from=$Payments item=_Payment}
			{assign_array var="TotalPaymentsAmount" index=$_Payment.CurrencyISO3 value=$TotalPaymentsAmount[$_Payment.CurrencyISO3]+$_Payment.Amount}
		<tr class="{cycle values='gridline,gridline1' name=c2}">
			<td>P-{$_Payment.pID}</td>
			<td>{$_Payment.xDate}</td>
			<td>{$_Payment.Description}</td>
			<td nowrap="nowrap">{$_Payment.Amount} {$_Payment.CurrencyISO3}</td>
			<td class="normal"><a href="#" onclick="open_window('{"sub_page=edit_payment&pID=`$_Payment.pID`"|set_query}',500,400); return false;">{"btn_edit"|translate}</a></td>
			<td><a href="javascript:void(0)" onclick="
				if(!confirm('{"cnfrm_areyousure"|translate}'))return false;
				document.form_delete_payment.elements['PAYMENT[pID]'].value = {$_Payment.pID};
				document.form_delete_payment.submit();
				return false;
				" title="{"btn_delete"|translate}"><img src="images_common/remove.gif" alt="{"btn_delete"|translate}" /></a></td>
		</tr>
		{/foreach}
		<tr class="background1 gridsfooter">
			<td colspan="1" valign="top">
				<strong>{"str_total"|translate}</strong>
			</td>
			<td colspan="5" align="right">
				<table align="right">
				{foreach from=$TotalPaymentsAmount key=_key item=_total}
					<tr><td align="right" style="border-width:0px;padding:0px">{$_total|string_format:"%.2f"} {$_key}</td></tr>
				{/foreach}
				</table>
			</td>
		</tr>
	</table>
{elseif $show_tables}
	<br /><br />{"affp_msg_nopayments_found"|translate}
{/if}{* if $PaymentsNumber and $show_tables *}

{if $PaymentsNumber and $CommissionsNumber and $show_tables}
	<hr />
	{* balance *}
	<table width="100%" class="grid">
		<tr class="background1">
			<td valign="top">
			<strong>{"affp_user_balance"|translate}</strong>
			</td>
			<td align="right">
				<table align="right">
				{foreach from=$CurrencyISO3 item=_currency}
				{if $TotalCommissionsAmount[$_currency.currency_iso_3] or $TotalPaymentsAmount[$_currency.currency_iso_3]}
					<tr>
						<td align="right" style="border-width:0px;padding:0px">
						{"`$TotalCommissionsAmount[$_currency.currency_iso_3]-$TotalPaymentsAmount[$_currency.currency_iso_3]`"|string_format:"%.2f"}
						{$_currency.currency_iso_3}
						</td>
					</tr>
				{/if}
				{/foreach}
				</table>
			</td>
		</tr>
	</table>
{/if}{* if $PaymentsNumber and $CommissionsNumber and $show_tables *}

<br />
</td>
</tr>
</table>